<template>
  <div class="objectives-container" ref="container">
    <svg ref="connectionsLayer" class="connections-layer"></svg>
    <div class="header-section">
      <h1 class="text-2xl font-bold">目标管理</h1>
      <div class="filters">
        <select v-model="selectedStatus" class="filter-select">
          <option value="">所有状态</option>
          <option value="not_started">未开始</option>
          <option value="in_progress">进行中</option>
          <option value="completed">已完成</option>
          <option value="cancelled">已取消</option>
        </select>
      </div>
    </div>

    <!-- 三列目标布局 -->
    <div class="objectives-three-columns" v-if="!loading">
      <!-- 部门级目标 -->
      <div class="objectives-column department-column">
        <div class="column-header">
          <h2>部门级目标</h2>
        </div>
        <div class="objectives-list">
          <div v-for="objective in departmentObjectives" :key="objective.id" 
               :id="`objective-${objective.id}`"
               class="objective-card level-department"
               @mouseenter="showTooltip(objective, $event)" 
               @mouseleave="hideTooltip()">
            <div v-if="objective.parent" class="connection-point left"></div>
            <div v-if="hasChildren(objective)" class="connection-point right"></div>
        <div class="objective-header">
          <div class="header-left">
            <span class="level-badge" :class="getObjectiveLevelClass(objective.level)">
              {{ getLevelLabel(objective.level) }}
            </span>
            <h2 class="text-lg font-semibold">{{ objective.title }}</h2>
          </div>
          <div class="objective-actions">
            <button @click="showKeyResults(objective)" class="action-btn view-btn" title="查看关键结果">
              <i class="fas fa-list"></i>
            </button>
            <button @click="editObjective(objective)" class="action-btn edit-btn" title="编辑目标">
              <i class="fas fa-edit"></i>
            </button>
            <button @click="confirmDelete(objective)" class="action-btn delete-btn" title="删除目标">
              <i class="fas fa-trash"></i>
            </button>
          </div>
        </div>

            <div class="objective-header">
              <div class="header-left">
                <h2 class="text-lg font-semibold">{{ objective.title }}</h2>
              </div>
              <div class="objective-actions">
                <button @click.stop="editObjective(objective)" class="action-btn edit-btn" title="编辑目标">
                  <i class="fas fa-edit"></i>
                </button>
              </div>
            </div>

            <div class="objective-body">
              <div class="meta-info">
                <span class="status-badge" :class="getStatusClass(objective.status)">
                  {{ getStatusLabel(objective.status) }}
                </span>
              </div>
              
              <!-- 进度条 -->
              <div class="progress-section">
                <div class="progress-bar">
                  <div class="progress" :style="{ width: `${getObjectiveProgress(objective)}%` }"
                       :class="getProgressClass(getObjectiveProgress(objective))">
                  </div>
                </div>
                <span class="progress-text">{{ getObjectiveProgress(objective) }}%</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 团队级目标 -->
      <div class="objectives-column team-column">
        <div class="column-header">
          <h2>团队级目标</h2>
        </div>
        <div class="objectives-list">
          <div v-for="objective in teamObjectives" :key="objective.id" 
               :id="`objective-${objective.id}`"
               class="objective-card level-team"
               @mouseenter="showTooltip(objective, $event)" 
               @mouseleave="hideTooltip()">
            <div class="objective-header">
              <div class="header-left">
                <h2 class="text-lg font-semibold">{{ objective.title }}</h2>
              </div>
              <div class="objective-actions">
                <button @click.stop="editObjective(objective)" class="action-btn edit-btn" title="编辑目标">
                  <i class="fas fa-edit"></i>
                </button>
              </div>
            </div>

            <div class="objective-body">
              <div class="meta-info">
                <span class="status-badge" :class="getStatusClass(objective.status)">
                  {{ getStatusLabel(objective.status) }}
                </span>
              </div>
              
              <!-- 进度条 -->
              <div class="progress-section">
                <div class="progress-bar">
                  <div class="progress" :style="{ width: `${getObjectiveProgress(objective)}%` }"
                       :class="getProgressClass(getObjectiveProgress(objective))">
                  </div>
                </div>
                <span class="progress-text">{{ getObjectiveProgress(objective) }}%</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 个人级目标 -->
      <div class="objectives-column personal-column">
        <div class="column-header">
          <h2>个人级目标</h2>
        </div>
        <div class="objectives-list">
          <div v-for="objective in personalObjectives" :key="objective.id" 
               :id="`objective-${objective.id}`"
               class="objective-card level-personal"
               @mouseenter="showTooltip(objective, $event)" 
               @mouseleave="hideTooltip()">
            <div class="objective-header">
              <div class="header-left">
                <h2 class="text-lg font-semibold">{{ objective.title }}</h2>
              </div>
              <div class="objective-actions">
                <button @click.stop="editObjective(objective)" class="action-btn edit-btn" title="编辑目标">
                  <i class="fas fa-edit"></i>
                </button>
              </div>
            </div>

            <div class="objective-body">
              <div class="meta-info">
                <span class="status-badge" :class="getStatusClass(objective.status)">
                  {{ getStatusLabel(objective.status) }}
                </span>
              </div>
              
              <!-- 进度条 -->
              <div class="progress-section">
                <div class="progress-bar">
                  <div class="progress" :style="{ width: `${getObjectiveProgress(objective)}%` }"
                       :class="getProgressClass(getObjectiveProgress(objective))">
                  </div>
                </div>
                <span class="progress-text">{{ getObjectiveProgress(objective) }}%</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 目标连线 SVG 层 -->
      <svg class="connections-layer" ref="connectionsLayer"></svg>
    </div>

    <!-- 加载状态 -->
    <div v-if="loading" class="loading-spinner">
      <i class="fas fa-spinner fa-spin"></i> 加载中...
    </div>

    <!-- 详细信息悬浮提示框 -->
    <div v-if="tooltip.show" class="objective-tooltip" :style="tooltip.style">
      <h3 class="tooltip-title">{{ tooltip.objective.title }}</h3>
      <p class="tooltip-description">{{ tooltip.objective.description || '暂无描述' }}</p>
      <div class="tooltip-meta">
        <div class="tooltip-dates">
          <span>开始: {{ formatDate(tooltip.objective.start_date) }}</span>
          <span>结束: {{ formatDate(tooltip.objective.end_date) }}</span>
        </div>
        <div class="tooltip-progress">
          <span>进度: {{ getObjectiveProgress(tooltip.objective) }}%</span>
        </div>
      </div>
      <div class="tooltip-actions">
        <button @click="showKeyResults(tooltip.objective)" class="tooltip-btn">
          查看关键结果
        </button>
        <button @click="confirmDelete(tooltip.objective)" class="tooltip-btn delete">
          删除
        </button>
      </div>
    </div>

    <!-- 添加目标按钮 -->
    <button @click="showObjectiveForm" class="add-objective-btn">
      <i class="fas fa-plus"></i> 添加新目标
    </button>

    <!-- 目标表单对话框 -->
    <div v-if="showForm" class="modal-overlay" @click.self="closeForm">
      <div class="modal-content">
        <h2 class="modal-title">{{ formTitle }}</h2>
        <form @submit.prevent="submitObjectiveForm" class="objective-form">
          <div class="form-group">
            <label for="title">标题</label>
            <input v-model="form.title" id="title" type="text" required>
          </div>
          <div class="form-group">
            <label for="description">描述</label>
            <textarea v-model="form.description" id="description" rows="3"></textarea>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label for="level">层级</label>
              <select v-model="form.level" id="level" required>
                <option value="department">部门级</option>
                <option value="team">团队级</option>
                <option value="personal">个人级</option>
              </select>
            </div>
            <div class="form-group">
              <label for="status">状态</label>
              <select v-model="form.status" id="status" required>
                <option value="not_started">未开始</option>
                <option value="in_progress">进行中</option>
                <option value="completed">已完成</option>
                <option value="cancelled">已取消</option>
              </select>
            </div>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label for="start_date">开始日期</label>
              <input v-model="form.start_date" id="start_date" type="date" required>
            </div>
            <div class="form-group">
              <label for="end_date">结束日期</label>
              <input v-model="form.end_date" id="end_date" type="date" required>
            </div>
          </div>
          <div class="form-actions">
            <button type="button" @click="closeForm" class="cancel-btn">取消</button>
            <button type="submit" class="submit-btn">{{ submitButtonText }}</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed, onMounted, watch, nextTick } from 'vue';
import { useObjectivesStore } from '../store/objectives';
import { storeToRefs } from 'pinia';
import { ElMessage } from 'element-plus';

export default defineComponent({
  name: 'Objectives',
  setup() {
    const store = useObjectivesStore();
    const { objectives, loading, error } = storeToRefs(store);
    
    const selectedStatus = ref('');
    const showForm = ref(false);
    const editingObjective = ref(null);
    const connectionsLayer = ref(null);
    const container = ref(null);
    
    const form = ref({
      title: '',
      description: '',
      level: 'personal',
      status: 'not_started',
      start_date: new Date().toISOString().split('T')[0],
      end_date: '',
      parent: null
    });

    // 计算属性：按层级分类的目标列表
    const departmentObjectives = computed(() => 
      objectives.value.filter(obj => obj.level === 'department' && (selectedStatus.value ? obj.status === selectedStatus.value : true))
    );
    const teamObjectives = computed(() => 
      objectives.value.filter(obj => obj.level === 'team' && (selectedStatus.value ? obj.status === selectedStatus.value : true))
    );
    const personalObjectives = computed(() => 
      objectives.value.filter(obj => obj.level === 'personal' && (selectedStatus.value ? obj.status === selectedStatus.value : true))
    );

    // 表单标题和按钮文本
    const formTitle = computed(() => editingObjective.value ? '编辑目标' : '创建新目标');
    const submitButtonText = computed(() => editingObjective.value ? '保存修改' : '创建目标');

    // 悬浮提示框
    const tooltip = ref({
      show: false,
      objective: null,
      style: {
        top: '0px',
        left: '0px'
      }
    });

    const showTooltip = (objective, event) => {
      tooltip.value.show = true;
      tooltip.value.objective = objective;
      tooltip.value.style = {
        top: `${event.clientY + 10}px`,
        left: `${event.clientX + 10}px`
      };
    };

    const hideTooltip = () => {
      tooltip.value.show = false;
    };

    // 绘制连线
    const drawConnections = () => {
      if (!connectionsLayer.value) return;

      const svg = connectionsLayer.value;
      svg.innerHTML = '';

      // 设置SVG视口
      svg.setAttribute('width', '100%');
      svg.setAttribute('height', '100%');

      // 创建连线分组
      const connectionGroup = document.createElementNS('http://www.w3.org/2000/svg', 'g');
      connectionGroup.setAttribute('class', 'connections');
      svg.appendChild(connectionGroup);

      // 收集所有连线信息
      const connections = [];
      objectives.value.forEach(objective => {
        if (objective.parent) {
          const parent = objectives.value.find(obj => obj.id === objective.parent);
          if (parent) {
            const parentEl = document.getElementById(`objective-${parent.id}`);
            const childEl = document.getElementById(`objective-${objective.id}`);

            if (parentEl && childEl) {
              connections.push({ parent: parentEl, child: childEl });
            }
          }
        }
      });

      // 延迟绘制连线，确保DOM完全更新
      setTimeout(() => {
        connections.forEach(({ parent, child }) => {
          const parentRect = parent.getBoundingClientRect();
          const childRect = child.getBoundingClientRect();
          const svgRect = svg.getBoundingClientRect();

          // 判断父子目标的相对位置
          const isParentOnLeft = parentRect.left < childRect.left;

          // 计算连线的起点和终点
          const startX = isParentOnLeft ? parentRect.right - svgRect.left : parentRect.left - svgRect.left;
          const startY = parentRect.top + parentRect.height / 2 - svgRect.top;
          const endX = isParentOnLeft ? childRect.left - svgRect.left : childRect.right - svgRect.left;
          const endY = childRect.top + childRect.height / 2 - svgRect.top;

          // 计算控制点（使用更自然的曲线）
          const deltaX = endX - startX;
          const controlPointOffset = Math.min(Math.abs(deltaX) * 0.3, 50);
          const controlPoint1X = startX + (isParentOnLeft ? controlPointOffset : -controlPointOffset);
          const controlPoint2X = endX - (isParentOnLeft ? controlPointOffset : -controlPointOffset);

          // 创建路径
          const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
          const d = `M ${startX} ${startY} 
                    C ${controlPoint1X} ${startY},
                      ${controlPoint2X} ${endY},
                      ${endX} ${endY}`;

          path.setAttribute('d', d);
          path.setAttribute('stroke', '#4299e1');
          path.setAttribute('stroke-width', '2');
          path.setAttribute('fill', 'none');
          path.setAttribute('class', 'connection-path');

          connectionGroup.appendChild(path);
        });
      }, 100);
    };

    // 监听目标列表变化，重新绘制连线
    watch([departmentObjectives, teamObjectives, personalObjectives], () => {
      nextTick(() => {
        drawConnections();
      });
    });

    // 生命周期钩子
    onMounted(async () => {
      await store.fetchObjectives();
      nextTick(() => {
        drawConnections();
      });
    });

    // 获取目标进度
    const getObjectiveProgress = (objective) => {
      if (!objective.key_results || objective.key_results.length === 0) {
        return 0;
      }
      const totalProgress = objective.key_results.reduce((sum, kr) => sum + kr.progress, 0);
      return Math.round(totalProgress / objective.key_results.length);
    };

    // 检查目标是否有子目标
    const hasChildren = (objective) => {
      return objectives.value.some(obj => obj.parent === objective.id);
    };

    // 显示/隐藏关键结果
    const showKeyResults = async (objective) => {
      if (!objective.keyResults) {
        try {
          const keyResults = await store.fetchKeyResults(objective.id);
          objective.keyResults = keyResults;
        } catch (error) {
          console.error('Error fetching key results:', error);
        }
      }
      objective.showKeyResults = !objective.showKeyResults;
    };

    // 格式化日期
    const formatDate = (date) => {
      if (!date) return '';
      return new Date(date).toLocaleDateString('zh-CN');
    };

    // 获取状态标签
    const getStatusLabel = (status) => {
      const statusMap = {
        not_started: '未开始',
        in_progress: '进行中',
        completed: '已完成',
        cancelled: '已取消'
      };
      return statusMap[status] || status;
    };

    // 获取层级标签
    const getLevelLabel = (level) => {
      const levelMap = {
        department: '部门',
        team: '团队',
        personal: '个人'
      };
      return levelMap[level] || level;
    };

    // 获取状态类名
    const getStatusClass = (status) => {
      const classMap = {
        not_started: 'status-not-started',
        in_progress: 'status-in-progress',
        completed: 'status-completed',
        cancelled: 'status-cancelled'
      };
      return classMap[status] || '';
    };

    // 获取层级类名
    const getObjectiveLevelClass = (level) => {
      const classMap = {
        department: 'level-department',
        team: 'level-team',
        personal: 'level-personal'
      };
      return classMap[level] || '';
    };

    // 获取进度条类名
    const getProgressClass = (progress) => {
      if (progress >= 100) return 'progress-complete';
      if (progress >= 70) return 'progress-good';
      if (progress >= 30) return 'progress-warning';
      return 'progress-danger';
    };

    // 表单相关方法
    const showObjectiveForm = (objective = null) => {
      if (objective) {
        console.log('编辑目标:', objective);
        // 确保我们有完整的目标对象，包括ID
        if (!objective.id) {
          ElMessage.error('目标数据不完整，无法编辑');
          return;
        }
        
        editingObjective.value = { ...objective }; // 使用浅拷贝避免引用问题
        
        // 确保所有必要的字段都存在
        form.value = {
          title: objective.title || '',
          description: objective.description || '',
          level: objective.level || 'personal',
          status: objective.status || 'not_started',
          start_date: objective.start_date || new Date().toISOString().split('T')[0],
          end_date: objective.end_date || '',
          parent: objective.parent || null
        };
      } else {
        editingObjective.value = null;
        // 新建目标的默认值
        form.value = {
          title: '',
          description: '',
          level: 'personal',
          status: 'not_started',
          start_date: new Date().toISOString().split('T')[0],
          end_date: '',
          parent: null
        };
      }
      showForm.value = true;
    };

    // 编辑目标
    const editObjective = (objective) => {
      showObjectiveForm(objective);
    };

    const closeForm = () => {
      showForm.value = false;
      editingObjective.value = null;
    };

    const submitObjectiveForm = async () => {
      try {
        // 准备表单数据
        const formData = { ...form.value };

        if (editingObjective.value) {
          // 编辑现有目标
          const objectiveId = editingObjective.value.id;
          console.log('编辑目标ID:', objectiveId);
          
          if (!objectiveId) {
            ElMessage.error('目标ID不存在，无法更新');
            return;
          }
          
          await store.updateObjective(objectiveId, formData);
          ElMessage.success('目标更新成功');
        } else {
          // 创建新目标
          await store.createObjective(formData);
          ElMessage.success('目标创建成功');
        }
        
        // 刷新目标列表
        await store.fetchObjectives();
        closeForm();
      } catch (error) {
        console.error('Error submitting form:', error);
        ElMessage.error(error.message || '保存失败');
      }
    };

    // 删除目标
    const confirmDelete = async (objective) => {
      if (confirm('确定要删除这个目标吗？')) {
        try {
          await store.deleteObjective(objective.id);
        } catch (error) {
          console.error('Error deleting objective:', error);
        }
      }
    };

    // 生命周期钩子
    onMounted(async () => {
      await store.fetchObjectives();
    });

    return {
      objectives,
      showTooltip,
      hideTooltip,
      drawConnections,
      container,
      connectionsLayer,
      departmentObjectives,
      teamObjectives,
      personalObjectives,
      hasChildren,
      closeForm,
      submitObjectiveForm,
      getObjectiveProgress,
      showKeyResults,
      formatDate,
      getStatusLabel,
      getLevelLabel,
      getStatusClass,
      getObjectiveLevelClass,
      getProgressClass,
      tooltip,
      form,
      showForm,
      editingObjective,
      selectedStatus,
      showObjectiveForm,
      loading,
      formTitle,
      submitButtonText,
      editObjective,
      confirmDelete
    };
  }
});
</script>

<style scoped>
.connection-path {
  opacity: 0.6;
  transition: all 0.3s ease;
}

.connection-path:hover {
  opacity: 1;
  stroke-width: 3;
}
.objectives-container {
  width: 100%;
  height: calc(100vh - 64px);
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.header-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 0 16px;
}

.objectives-three-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  height: calc(100% - 60px);
  position: relative;
  padding: 0 16px;
}

.objectives-column {
  background-color: #f7fafc;
  border-radius: 8px;
  padding: 12px;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.objectives-column .objectives-list {
  overflow-y: auto;
  flex-grow: 1;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.objectives-column .objectives-list::-webkit-scrollbar {
  width: 4px;
}

.objectives-column .objectives-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 2px;
}

.objectives-column .objectives-list::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 2px;
}

.objectives-column .objectives-list::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

.column-header {
  padding: 8px;
  margin-bottom: 12px;
  border-bottom: 2px solid #e2e8f0;
}

.column-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: #2d3748;
}

.connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.connections {
  opacity: 1;
}

.objective-tooltip {
  position: fixed;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  padding: 16px;
  max-width: 300px;
  z-index: 1000;
}

.tooltip-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #2d3748;
}

.tooltip-description {
  font-size: 14px;
  color: #4a5568;
  margin-bottom: 12px;
  line-height: 1.4;
}

.tooltip-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  color: #718096;
}

.tooltip-dates {
  display: flex;
  justify-content: space-between;
}

.tooltip-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.tooltip-btn {
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  background-color: #edf2f7;
  border: none;
  color: #4a5568;
  transition: all 0.2s ease;
}

.tooltip-btn:hover {
  background-color: #e2e8f0;
}

.tooltip-btn.delete {
  background-color: #fed7d7;
  color: #c53030;
}

.tooltip-btn.delete:hover {
  background-color: #feb2b2;
}

.filters {
  display: flex;
  gap: 12px;
}

.filter-select {
  padding: 6px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background-color: white;
}

.objectives-list {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.objective-card {
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  margin: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  position: relative;
}

.connection-point {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 2px;
  background-color: #4299e1;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.connection-point.left {
  left: -16px;
}

.connection-point.right {
  right: -16px;
}

.objective-card:hover .connection-point {
  opacity: 1;
}

.objective-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 1;
}

.objective-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #e2e8f0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.header-left h2 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  margin: 0;
}

.level-badge {
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

/* 列样式 */
.department-column {
  border-top: 3px solid #4299e1;
}

.team-column {
  border-top: 3px solid #68d391;
}

.personal-column {
  border-top: 3px solid #f6ad55;
}

.level-department {
  background-color: #ebf8ff;
  color: #2b6cb0;
}

.level-team {
  background-color: #f0fff4;
  color: #2f855a;
}

.level-personal {
  background-color: #fff5f5;
  color: #c53030;
}

.objective-body {
  padding: 10px;
}

.description {
  color: #4a5568;
  margin-bottom: 10px;
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 4px;
}

.status-badge {
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

.status-not-started {
  background-color: #e2e8f0;
  color: #4a5568;
}

.status-in-progress {
  background-color: #ebf8ff;
  color: #2b6cb0;
}

.status-completed {
  background-color: #f0fff4;
  color: #2f855a;
}

.status-cancelled {
  background-color: #fff5f5;
  color: #c53030;
}

.date-info {
  font-size: 11px;
  color: #718096;
  white-space: nowrap;
}

.progress-section {
  margin-top: 8px;
}

.progress-bar {
  height: 4px;
  background-color: #e2e8f0;
  border-radius: 2px;
  overflow: hidden;
}

.progress {
  height: 100%;
  transition: width 0.3s ease;
}

.progress-text {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: #718096;
  text-align: right;
}

.progress-warning {
  background-color: #ecc94b;
}

.progress-danger {
  background-color: #f56565;
}

/* 删除重复的 progress-text 样式，因为前面已经定义过了 */

.key-results-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
}

.key-result-card {
  background-color: #f7fafc;
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 8px;
}

.kr-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.kr-title {
  font-size: 14px;
  font-weight: 500;
}

.kr-progress {
  font-size: 12px;
  color: #718096;
}

.add-kr-btn {
  margin-top: 8px;
  padding: 4px 8px;
  font-size: 12px;
  color: #4a5568;
  background-color: #edf2f7;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.add-kr-btn:hover {
  background-color: #e2e8f0;
}

.objective-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.objective-card:hover .objective-actions {
  opacity: 1;
}

.action-btn {
  padding: 4px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 3px;
  transition: background-color 0.2s ease;
  font-size: 12px;
}

.view-btn {
  color: #4a5568;
}

.edit-btn {
  color: #4a5568;
}

.delete-btn {
  color: #e53e3e;
}

.action-btn:hover {
  background-color: #edf2f7;
}

.add-objective-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 24px;
  background-color: #4299e1;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: background-color 0.2s ease;
}

.add-objective-btn:hover {
  background-color: #3182ce;
}

.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: #4a5568;
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
}

.objective-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group label {
  font-size: 14px;
  font-weight: 500;
  color: #4a5568;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 14px;
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.cancel-btn {
  padding: 8px 16px;
  background-color: #e2e8f0;
  color: #4a5568;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.submit-btn {
  padding: 8px 16px;
  background-color: #4299e1;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.cancel-btn:hover {
  background-color: #cbd5e0;
}

.submit-btn:hover {
  background-color: #3182ce;
}
</style>